//
//  IosHelper.swift
//  Runner
//
//  Created by guo on 2021/11/13.
//

import Foundation



public class IosHelper {
    
    /**
     flutter跳转ios原生界面，及返回
     */
    public static func toIos(uiCtl: UINavigationController?
         , fCtl:FlutterViewController ){
        let testChannel = FlutterMethodChannel(name: "samples.flutter.dev/goToNativePage",
                                               binaryMessenger: fCtl.binaryMessenger)
        testChannel.setMethodCallHandler({
            (call: FlutterMethodCall, result: FlutterResult) -> Void in
            
            let arguments = call.arguments as! NSDictionary
            
            guard call.method == "goToNativePage" else {
                result(FlutterMethodNotImplemented)
                return
            }
            
            /*
            // 通过91淘金CPL平台分配的 appKey 启动SDK，注：该方法需要在主线程中调用
                TJSDK.registerClient(withAppId: "1234", appKey: "12345")

                //可以绑定您的APP用户，参数为您APP用户的唯一值
                TJSDK.appUserId = "abc123"
             
             
                //self 为弹出列表的上一级ViewController
                TJSDK.present(self)
             */
            
            
            
  //          AMapServices.shared().apiKey = "您的Key"
            
            
            
            print("跳转")
            let vc: UIViewController = NativeViewController()
            vc.navigationItem.title = arguments["test"] as! String; uiCtl?.pushViewController(vc, animated: true)
            
            //self?.goToNativePage(result: result, title: arguments["test"] as! String)
        })
        
    }
    
    
    
    /**
     示例
     var navigationController: UINavigationController?
       
     override func application(
       _ application: UIApplication,
       didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
     ) -> Bool {
       GeneratedPluginRegistrant.register(with: self)
       
       let controller = FlutterViewController()
       
       self.navigationController = UINavigationController.init(rootViewController: controller)
       window = UIWindow(frame: UIScreen.main.bounds)
       window?.rootViewController = self.navigationController
       window?.makeKeyAndVisible()
       

       
       let testChannel = FlutterMethodChannel(name: "samples.flutter.dev/goToNativePage",
                                                 binaryMessenger: controller)
       testChannel.setMethodCallHandler({
           [weak self] (call: FlutterMethodCall, result: FlutterResult) -> Void in
           
           let arguments = call.arguments as! NSDictionary
           
           guard call.method == "goToNativePage" else {
               result(FlutterMethodNotImplemented)
               return
           }
           
           self?.goToNativePage(result: result, title: arguments["test"] as! String)
       })
       
       
       
       return super.application(application, didFinishLaunchingWithOptions: launchOptions)
     }
       
       
       private func goToNativePage(result: FlutterResult,title: String) {
           print("跳转")
           let vc: UIViewController = NativeViewController()
           vc.navigationItem.title = title
           self.navigationController?.pushViewController(vc, animated: true)
       }
     */
    
    


}
